package org.jeecg.modules.demo3.peijian.service.impl;



import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.jeecg.modules.demo3.peijian.entity.AxhkAllResistance;
import org.jeecg.modules.demo3.peijian.entity.AxhkXxwyLinearRegulato;
import org.jeecg.modules.demo3.peijian.entity.materials.Rental;
import org.jeecg.modules.demo3.peijian.mapper.AxhkAllResistanceMapper;
import org.jeecg.modules.demo3.peijian.service.IAxhkAllResistanceService;
import org.jeecg.modules.demo3.peijian.utill.AddObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.List;
import java.util.Map;

/**
 * @Description: 所有配件
 * @Author: jeecg-boot
 * @Date:   2021-04-15
 * @Version: V1.0
 */
@Service
public class AxhkAllResistanceServiceImpl extends ServiceImpl<AxhkAllResistanceMapper, AxhkAllResistance> implements IAxhkAllResistanceService {

    @Autowired
    private AxhkAllResistanceMapper axhkAllResistanceMapper;

    //计算所有 现有数量 计算所有购买金额
    @Override
    public Rental AtAxhkAllResistance() {
        List<Map<String,Object>> axhkXxwyLinearRegulato = axhkAllResistanceMapper.getAxhkAllResistance();
        Rental rental = new Rental();
        int number = 0;//剩余总数量
        Double retal = 0.0;// 一栏 总金额
        for(int i = 0;i<axhkXxwyLinearRegulato.size();i++){
            Integer h = (Integer) axhkXxwyLinearRegulato.get(i).get("price_per_num");
            Double r = (Double)axhkXxwyLinearRegulato.get(i).get("price_per_unit");
            String n = (String)axhkXxwyLinearRegulato.get(i).get("now_number");
            if(null != r && null != h){
                Integer num = (int) axhkXxwyLinearRegulato.get(i).get("price_per_num");//购买数量
                Double reta = (Double)axhkXxwyLinearRegulato.get(i).get("price_per_unit");//购买单价
                // 购买总价格 Double.parseDouble
                retal = retal+(num*reta);
            }
            if(null != n){
                String numb = (String)axhkXxwyLinearRegulato.get(i).get("now_number");//现有数量
                //有些数值从在 ≥290
                String a = numb.substring(0,1);
                //判断如有 范围数值 一切按 =数值计算
                if(a.equals("≥")){
                    String b = numb.substring(1,numb.length());
                    int numbers = Integer.valueOf(b).intValue();
                    // 现有总数量
                    number = number+numbers;
                }else {
                    int numbers = Integer.valueOf(numb).intValue();
                    // 现有总数量
                    number = number+numbers;
                }
            }
        }
        //获取小数点后两位
        BigDecimal b = BigDecimal.valueOf(retal).setScale(2, BigDecimal.ROUND_HALF_UP);
        Double retals = b.doubleValue();
        //进行添加
        rental.setNumber(number);
        rental.setRetals(retals);
        return rental ;
    }

}
